﻿// -----------------------------------------------------------------------
// <copyright file="TestingClass.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System.Data;
using ASS.BUS.DTO;

namespace ASS
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NUnit.Framework;
    using ASS.BUS.Services;
    using ASS.DAO;


    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [TestFixture]
    public class TestingClass
    {
        DataContext _db = new DataContext();

#region TestBenhNhan
        BenhNhanServices _benhNhanServices = new BenhNhanServices();      
        
        [Test]
        public void TestAddBenhNhan()
        {
            BenhNhan bn = new BenhNhan()
            {
                Ten = "Kiem tra benh nhan",
                DiaChi = "test123456789",
                NgaySinh = "2/2/2014",
            };
           
            Assert.True(_benhNhanServices.Add(bn), "True");
            
            BenhNhan bn1 = new BenhNhan()
            {
                DiaChi = "test123456789",
                NgaySinh = "2/2/2014",
            };

            Assert.False(_benhNhanServices.Add(bn1), "False");

            //BenhNhan bn2 = new BenhNhan()
            //{
            //    Ten = "Kiem tra benh nhan",
            //    DiaChi = "test123456789",
            //    NgaySinh = "2/2/2014",
            //    MaBn = 1,
            //};
            //Assert.False(_benhNhanServices.Add(bn2), "False");

        }

        [Test]
        public void TestGetBenhNhan()
        {
           
            var bn = _db.BenhNhans.FirstOrDefault(x => x.Ten == "Kiem tra benh nhan");

            if (bn != null)
            {
                var id = bn.MaBn;
                BenhNhan benhNhan = _benhNhanServices.GetBenhNhan(id);
                Assert.AreEqual(benhNhan.DiaChi, bn.DiaChi);
            }
        }

        [Test]
        public void TestGetBenhNhans()
        {
            var benhNhans = _benhNhanServices.GetBenhNhans();

            Assert.NotNull(benhNhans);
        }

        [Test]
        public void TestEditBenhNhan()
        {
            var bn = _db.BenhNhans.FirstOrDefault(x => x.Ten == "Kiem tra benh nhan");

            if (bn != null) bn.Ten = "Edited Kiem tra benh nhan";

            Assert.True(_benhNhanServices.EditBenhNhan(bn), "kiem tra thanh cong");
            if (bn != null) Assert.AreEqual(bn.Ten, "Edited Kiem tra benh nhan");

            BenhNhan bn1 = new BenhNhan()
            {
                Ten = "sdasdsadsad",
                DiaChi = "test123456789",
                NgaySinh = "2/2/2014",
                MaBn = 20,
            };

            Assert.False(_benhNhanServices.EditBenhNhan(bn1), "Kiem tra that bai");      

        }

        [Test]
        public void TestDeleteBenhNhan()
        {
            var bn = _db.BenhNhans.FirstOrDefault(x => x.Ten == "Edited Kiem tra benh nhan");
            var id = 0;
            if (bn != null)
            {
                id = bn.MaBn;
            }
            Assert.Greater(id, 0, "Lon hon");

            Assert.True(_benhNhanServices.DeleteBenhNhan(id), "True");

            Assert.False(_benhNhanServices.DeleteBenhNhan(20), "False");
        }

#endregion

        #region TestDonThuoc
        DonThuocServices _donThuocServices = new DonThuocServices();

        [Test]
        public void TestAddDonThuoc()
        {
            BenhNhan bn = new BenhNhan()
            {
                Ten = "Test don thuoc",
                DiaChi = "testdonthuoc",
                NgaySinh = "2/2/2014",
            };

            Assert.True(_benhNhanServices.Add(bn), "True");

            var benhNhans = _db.BenhNhans.Where(x => x.Ten == "Test don thuoc").ToList();
            var id = 0;
            foreach (var benhNhan in benhNhans)
            {
                if (benhNhan.DiaChi == "testdonthuoc")
                {
                    id = benhNhan.MaBn;
                    break;
                };
            }

            DonThuoc dt = new DonThuoc()
            {
                ChuanDoan = "test chuan doan don thuoc",
                NgayKham = "2/2/2014",
                NgayTaiKham = "12/2/2014",
                DanDo = "Test dan do",
                MaBn = id,
            };

            Assert.True(_donThuocServices.Add(dt));

            var donThuocs = _db.DonThuocs.Where(x => x.MaBn == id && x.ChuanDoan == "test chuan doan don thuoc").ToList();

            foreach (var donThuoc in donThuocs)
            {
                if (donThuoc.NgayKham == "2/2/2014")
                {
                    Assert.False(_donThuocServices.Add(donThuoc));
                    break;
                }
            }
        }

        [Test]
        public void TestGetDonThuoc()
        {

            var dt = _db.DonThuocs.FirstOrDefault(x => x.ChuanDoan == "test chuan doan don thuoc");

            if (dt != null)
            {
                var id = dt.MaToa;
                DonThuoc donThuoc = _donThuocServices.GetDonThuoc(id);
                Assert.AreEqual(donThuoc.NgayKham, dt.NgayKham);
            }
        }

        [Test]
        public void TestGetDonThuocs()
        {
            var donThuocs = _donThuocServices.GetDonThuocs();

            Assert.NotNull(donThuocs);
        }

        [Test]
        public void TestDeleteDonThuoc()
        {
            var bn = _db.DonThuocs.FirstOrDefault(x => x.ChuanDoan == "test chuan doan don thuoc");
            var id = 0;
            if (bn != null)
            {
                id = bn.MaToa;
            }
            Assert.Greater(id, 0, "Lon hon");

            Assert.True(_donThuocServices.Delete(id), "True");

            Assert.False(_donThuocServices.Delete(20), "False");
        }
        #endregion

        #region TestLichHen
        LichHenServices _lichHenServices = new LichHenServices();

        [Test]
        public void TestAddLichHen()
        {
            LichHen lh = new LichHen()
            {
                NgayHen = "2/2/2014",
                SoDienThoai = "012287024",
                NoiDung = "Test noi dung don thuoc",
            };

            Assert.True(_lichHenServices.Add(lh), "Khong add duoc");
            var id = 0;
            var lichHen = _db.LichHens.FirstOrDefault(x => x.NoiDung == "Test noi dung don thuoc");
           
            
            id = lichHen.MaLh;

                LichHen lh1 = new LichHen()
                {
                    MaLh =  id,
                    NgayHen = "2/2/2014",
                    SoDienThoai = "!@$%^&fdd",
                    NoiDung = "asfasdasdasdas",
                };

            Assert.True(_lichHenServices.Add(lh1), id.ToString());
        }

        [Test]
        public void TestGetLichHen()
        {

            var lh = _db.LichHens.FirstOrDefault(x => x.SoDienThoai == "012287024");

            if (lh != null)
            {
                var id = lh.MaLh;
                LichHen lichHen = _lichHenServices.GetLichHen(id);
                Assert.AreEqual(lichHen.SoDienThoai, lh.SoDienThoai);
            }
        }

        [Test]
        public void TestGetLichHens()
        {
            var lichHens = _lichHenServices.GetLichHens();

            Assert.NotNull(lichHens);
        }

        [Test]
        public void TestEditLichHen()
        {
            var lh = _db.LichHens.FirstOrDefault(x => x.NoiDung == "Test noi dung don thuoc");

            if (lh != null) lh.NoiDung = "Edited noi dung don thuoc";

            Assert.True(_lichHenServices.EditLichHen(lh), "kiem tra thanh cong");
            if (lh != null) Assert.AreEqual(lh.NoiDung, "Edited noi dung don thuoc");

            LichHen lichHen = new LichHen()
            {
                NgayHen = "2/2/2014",
                SoDienThoai = "012287024",
                NoiDung = "Test noi dung don thuoc",
            };
            Assert.False(_lichHenServices.EditLichHen(lichHen));
        }

        [Test]
        public void TestDeleteLichHen()
        {
            var bn = _db.LichHens.FirstOrDefault(x => x.NoiDung == "Edited noi dung don thuoc");
            var id = 0;
            if (bn != null)
            {
                id = bn.MaLh;
            }
            Assert.Greater(id, 0, "Lon hon");

            Assert.True(_lichHenServices.Delete(id), "True");

            Assert.False(_lichHenServices.Delete(100), "False");
        }
        #endregion

        #region TestThuoc

        ThuocServices _thuocServices = new ThuocServices();

        [Test]
        public void TestAddThuoc()
        {
            var thuoc = new Thuoc()
            {
                Ten = "test thuoc",
                MieuTa = "test mieu ta",
            };

            Assert.True(_thuocServices.Add(thuoc));
        }

        [Test]
        public void TestGetThuoc()
        {
            var thuoc = _thuocServices.GetThuoc("test thuoc");

            Assert.AreEqual("test mieu ta", thuoc.MieuTa);
        }

        NhanVienServices _nhanVienServices = new NhanVienServices();

        #endregion

        #region NhanVien
        [Test]
        public void TestAddNhanVien()
        {
            var nv = new NhanVien()
            {
                Ten = "Kiem tra nv",
                DiaChi = "test123456789",
                NgaySinh = "2/2/2014",
            };

            Assert.True(_nhanVienServices.Add(nv), "Nhan vien da ton tai");
        }

        [Test]
        public void TestGetNhanVien()
        {

            var nv = _db.NhanViens.FirstOrDefault(x => x.Ten == "Kiem tra nv");

            if (nv != null)
            {
                var id = nv.MaNv;
                NhanVien nhanVien = _nhanVienServices.GetNhanVien(id);
                Assert.AreEqual(nhanVien.DiaChi, nv.DiaChi);
            }
        }

        [Test]
        public void TestGetNhanViens()
        {
            var nhanViens = _nhanVienServices.GetNhanViens();

            Assert.NotNull(nhanViens);
        }
    }

        #endregion
    //[TestFixture]
    //public class TestingBacSi
    //{
    //    NhanVienServices _nhanVienServices = new NhanVienServices();
    //    DataContext _db = new DataContext();

    //    [Test]
    //    public void TestAddNhanVien()
    //    {
    //        var nv = new NhanVien()
    //        {
    //            Ten = "Kiem tra nv",
    //            DiaChi = "test123456789",
    //            NgaySinh = "2/2/2014",
    //        };

    //        Assert.True(_nhanVienServices.Add(nv), "Nhan vien da ton tai");
    //    }

    //    [Test]
    //    public void TestGetNhanVien()
    //    {

    //        var nv = _db.NhanViens.FirstOrDefault(x => x.Ten == "Kiem tra nv");

    //        if (nv != null)
    //        {
    //            var id = nv.MaNv;
    //            NhanVien nhanVien = _nhanVienServices.GetNhanVien(id);
    //            Assert.AreEqual(nhanVien.DiaChi, nv.DiaChi);
    //        }
    //    }

    //    [Test]
    //    public void TestGetNhanViens()
    //    {
    //        var nhanViens = _nhanVienServices.GetNhanViens();

    //        Assert.NotNull(nhanViens);
    //    }    
    //}

    //[TestFixture]
    //public class TestingThuoc
    //{
    //    ThuocServices _thuocServices = new ThuocServices();
    //    DataContext _db = new DataContext();

    //    [Test]
    //    public void TestAddThuoc()
    //    {
    //        var thuoc = new Thuoc()
    //        {
    //            Ten = "test thuoc",
    //            MieuTa = "test mieu ta",
    //        };

    //        Assert.True(_thuocServices.Add(thuoc));
    //    }

    //    [Test]
    //    public void TestGetThuoc()
    //    {
    //        var thuoc = _thuocServices.GetThuoc("test thuoc");

    //        Assert.AreEqual("test mieu ta", thuoc.MieuTa);
    //    }

    //    [Test]
    //    public void TestGetNhanViens()
    //    {
    //        var thuocs = _thuocServices.GetThuocs();

    //        Assert.NotNull(thuocs);
    //    }    
    //}

    //[TestFixture]
    //public class TestingLichHen
    //{
    //    LichHenServices _lichHenServices = new LichHenServices();
    //    DataContext _db = new DataContext();

    //    [Test]
    //    public void TestAddLichHen()
    //    {
    //        LichHen lh = new LichHen()
    //        {  
    //            NgayHen = "2/2/2014",
    //            SoDienThoai = "012287024",
    //            NoiDung = "Test noi dung don thuoc",
    //        };

    //        Assert.True(_lichHenServices.Add(lh), "don thuoc da ton tai");
    //    }

    //    [Test]
    //    public void TestGetLichHen()
    //    {

    //        var lh = _db.LichHens.FirstOrDefault(x => x.SoDienThoai == "012287024");

    //        if (lh != null)
    //        {
    //            var id = lh.MaLh;
    //            LichHen lichHen = _lichHenServices.GetLichHen(id);
    //            Assert.AreEqual(lichHen.SoDienThoai, lh.SoDienThoai);
    //        }
    //    }

    //    [Test]
    //    public void TestGetLichHens()
    //    {
    //        var lichHens = _lichHenServices.GetLichHens();

    //        Assert.NotNull(lichHens);
    //    }

    //    [Test]
    //    public void TestEditLichHen()
    //    {
    //        var lh = _db.LichHens.FirstOrDefault(x => x.NoiDung == "Test noi dung don thuoc");

    //        if (lh != null) lh.NoiDung = "Edited noi dung don thuoc";

    //        Assert.True(_lichHenServices.EditLichHen(lh), "kiem tra thanh cong");
    //        if (lh != null) Assert.AreEqual(lh.NoiDung, "Edited noi dung don thuoc");
    //    }
    //}

    //[TestFixture]
    //public class TestingDonThuoc
    //{
    //    DonThuocServices _donThuocServices = new DonThuocServices();
    //    DataContext _db = new DataContext();

    //    [Test]
    //    public void TestAddDonThuoc()
    //    {
    //        DonThuoc dt = new DonThuoc()
    //        {
    //             ChuanDoan = "test chuan doan don thuoc",
    //             NgayKham = "2/2/2014",
    //             NgayTaiKham = "12/2/2014",
    //             DanDo =  "Test dan do",    
    //             MaBn = 1,
    //        };

    //        Assert.True(_donThuocServices.Add(dt), "don thuoc da ton tai");
    //    }

    //    [Test]
    //    public void TestGetDonThuoc()
    //    {

    //        var dt = _db.DonThuocs.FirstOrDefault(x => x.ChuanDoan == "test chuan doan don thuoc");

    //        if (dt != null)
    //        {
    //            var id = dt.MaToa;
    //            DonThuoc donThuoc = _donThuocServices.GetDonThuoc(id);
    //            Assert.AreEqual(donThuoc.NgayKham, dt.NgayKham);
    //        }
    //    }

    //    [Test]
    //    public void TestGetDonThuocs()
    //    {
    //        var donThuocs = _donThuocServices.GetDonThuocs();
            
    //        Assert.NotNull(donThuocs);
    //    }
    //}
}
